package com.yang.mybatis.proxy;

import com.yang.mybatis.config.MybatisConfiguration;
import com.yang.mybatis.session.IMybatisSqlSession;

import java.lang.reflect.Proxy;

public class MapperProxyFactory {

    private MybatisConfiguration mybatisConfiguration;

    public MapperProxyFactory(MybatisConfiguration mybatisConfiguration) {
        this.mybatisConfiguration = mybatisConfiguration;
    }

    public Object newInstance(Class mapperType, IMybatisSqlSession mybatisSqlSession) {
        MapperProxy mapperProxy = new MapperProxy(mapperType, mybatisSqlSession);
        return Proxy.newProxyInstance(mapperType.getClassLoader(),
                new Class[]{mapperType},
                mapperProxy);
    }

    public MybatisConfiguration getMybatisConfiguration() {
        return mybatisConfiguration;
    }
}